function onDeviceReady(){
    //
    if(('StatusBar' in window) == true){
        StatusBar.overlaysWebView(false);
        StatusBar.styleDefault();
        StatusBar.backgroundColorByHexString('#F8A233');
    }
    //
    if (navigator.splashscreen){
        navigator.splashscreen.hide();
    }

    // 获取版本号
    var callback = function(version){
        if(version != null){
            window.appVersion = version;
        }
    }
    cordova.getAppVersion(callback);

    // back button for android
    document.addEventListener("backbutton", handleBackButton, false);
}


var EXIT_COUNTER = 0; 
var handleBackButton = function(){
	// 子页面返回到父页面，主页则退出
	var url = window.location.hash;
	url = url.replace('#', '');
	// 客户
	if(url.indexOf('/client/detail') >= 0){
		window.location.hash = url.replace('/detail', '');
	}
	// 交易
	else if(url.indexOf('/trading/detail') >= 0){
		window.location.hash = url.replace('/detail', '');
	} 
	else{
		window.location.hash = '/'
		EXIT_COUNTER = EXIT_COUNTER + 1;
		if (EXIT_COUNTER == 3){
			navigator.notification.confirm("退出应用程序？", 
				function (button) {
					if( button == 1 ) {
						navigator.app.exitApp(); 
					} 
				}, "关闭", "确定,取消");
		}
	}
}

export { onDeviceReady }